home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / ellis / gc7.ps (.svg) < prev    next >
Encapsulated PostScript  |  1993-07-23  |  69KB  |  524x906  |  8-bit (133 colors)
Labels: black | darkness
OCR: intaa []a-a (39, a45, a57, a63, a79); SubArray<int>asa-aSUB (int, aa); ThedformosUB2 (type, aarray, ad2) createscubArray<Array<type, ad2>a>dhat accessesche elements@fadwo-dimensionaloarrayowhose@secondalimensiondhasad2elements. For example, intaa [] [4]a-a{{1, a2, a3, a4), a {5, a6, a7, a8} }; SubArray<Array<int, a4>a>asa-aSUB2 (int, aa, a4); createscubArrayasahat accessesche@oxolarrayooThedforms BUB3 (type, aarray, d2, ad3) and SUB4 (type, aarray, ad2, ad3, ad4) operate@nahree-canddour- dimensionalaurrays. Implementation notes Thesedemplateclassesaredimplemented without using@lassaderivation@orabstract base@lasses. The benefits faderivationovouldaccrue@onlyawithatheause@fovirtual functions, butovirtual functionsovouldaddooword@f@overheaddo@everyoarray.Thisosontolerable, sinceArrays, SubArrays,and DynArraysareantendeddodbeasofficientas built-in C++carrays. The approachaised here,dhree separateclassescandómplicit conversions betweendhem,dsqustas expressivedfordheprogrammer utomore efficient. With good compiler,dhe@only@overheadofasingaheseclassesinstead ofahedbuilt-in C++ equivalentscomes fromahearun-time@checks. Run-timewhecking Theorun-timechecks@andbedisabledat@compiledimedby definingahe preprocessorovariable CHECKING=0 beforeancludingahisdile. Of course,disabling@hecking@liminatesaheguarantee of safety provided byahe safe subset.dngeneral, programmers shoulddeavedhecheckscenabledas latednahe development processas possible,avenqperhapsonproduction@code.oWithoun-time checking,cadbuggy programdhaltscascooncassafetydsoviolated, beforedt@anproducedincorrect results. The exactomechanismofosignalingorun-time@errorsdsmotospecified by hisonterface.dn general,corun-time@errord(suchoscan@out-of-boundscindex)ascadbug, and programsoshould notary tochandlersucherrors. #pragmaisafe #includei<stdlib.h> template<iclassiTi>iclassiSubArrayi{ public: t iiiiintiNumber(); iiiiT&ioperatori [] (iintiii); iiiiSubArray<iTi>iSub (iintistart, iintinumberi); iiiiSubArray<iTi>iSub (iintistarti); iiiiSubArray<iTi>iSub (); iiiivoidiCopy (iSubArray<iTi>i); iiiiintioperatori== (iSubArray<iTi>i); iiiiintioperatori!=(iSubArray<iTi>i); iiiiintiEqual (iSubArray<iTi>i); #pragmaiunsafe iiiiSubArray (iT*it, iintinumberi); /*1CreatestatSubArraytoftnumbertelementstatt ,tti+il,...,lti+inumberi-il.t*/ 61